package cn.tianjindong.blog_manager.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.tianjindong.blog.common.pojo.PageView;
import cn.tianjindong.blog.pojo.BlogUser;
import cn.tianjindong.blog.pojo.BlogVisitlog;
import cn.tianjindong.blog_manager.service.UserService;

/**
 * 该类用于管理前台用户
 * @author 田 金 东
 *
 */
@Controller
public class UserManageController {
	
	@Autowired
	private UserService userService;
	
	/**
	 * 前往管理员登录日志界面
	 * 
	 * @param model
	 * @param currentPage
	 *            当前所在页
	 * @param countItem
	 *            每页显示条数
	 * @return
	 */
	@RequestMapping("/user-loginlog.html")
	public String toUserVisitLogPage(Model model, @RequestParam(defaultValue = "1") Integer currentPage,
			@RequestParam(defaultValue = "8") Integer countItem) {
		PageView<BlogVisitlog> pageView = userService.getUserVisitLogPageView(currentPage, countItem);
		model.addAttribute("pageView", pageView);
		return "/user-loginlog";
	}
	
	/**
	 * 前往前台用户管理界面
	 * @param model
	 * @param currentPage
	 * @param countItem
	 * @return
	 */
	@RequestMapping("/manage-user.html")
	public String toUserPageView(Model model, @RequestParam(defaultValue = "1") Integer currentPage,
			@RequestParam(defaultValue = "8") Integer countItem){
		PageView<BlogUser> pageView = userService.getUserPageView(currentPage, countItem);
		model.addAttribute("pageView", pageView);
		return "/manage-user";
	}
	
	@RequestMapping("/user/reverse-status.action")
	public @ResponseBody String reverseUserStatus(Long userId){
		userService.reverseUserStatus(userId);
		return "{\"status\":\"ok\"}";
	}
}
